<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport"
		content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<title>title</title>
	<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../css/aui.css" />
	<link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
	<link rel="stylesheet" type="text/css" href="../css/icons.css" />
	<script src="../script/jquery-1.9.1.min.js"></script>
	<script src="../script/bootstrap.min.js"></script>
	<style>
		.table tr:first-child {
			background: url(static/img/tableheader-bg.gif) no-repeat left top;
			background-color: #DCE9F2;
			border-top: 1px solid #CBD6DE;
			border-bottom: 1px solid #ADBECB;
			color: #467aa7;
			font-size: 13px;
			font-weight: bold;
		}

		.table {
			margin-bottom: 15px;
			width: 100%;
			border-collapse: collapse;
			font-size: 13px;
			margin-bottom: 15px;
			width: 100%;
			border-collapse: collapse;
		}

		.table td {
			height: 40px;
			text-align: center;
			border: 1px solid #CBD6DE;
			padding: 0;
			margin: 0;
			vertical-align: middle !important;
		}

		/*#chkHCTable{
				font-size: 10px;
		}*/
	</style>
</head>

<body>
	<header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
		<a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
			<span class="aui-iconfont aui-icon-left"></span>
		</a>
		<div class="aui-title" id="title">
			生成设备任务单
		</div>
	</header>
	<div class="aui-content" style="margin-top:50px;">

		<div class="aui-form">

			<div class="aui-content aui-margin-b-15">
				<ul class="aui-list aui-form-list" style="font-size: 14px;">
					<li class="aui-list-item">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-label" style="font-size: 14px;">父资产编码</div>
							<input type="text" class="aui-input" placeholder="请 扫描/输入 父资产编码"
								style="width: 80%;font-size: 14px;" id="sm">
							<i class="aui-input-addon aui-iconfont aui-icon-scan " style="font-size: 1.6rem"
								onclick="toScanner();"></i>
						</div>
					</li>
					<li class="aui-list-item">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-label" style="font-size: 14px;">子设备编码</div>
							<input type="text" class="aui-input" placeholder="选择子设备编码"
								style="width: 80%;font-size: 14px;" id="sonEquip" value=""
								onclick="goSelectSonEquip()">
							<i class="aui-input-addon aui-iconfont aui-icon-right" style="font-size: 1.6rem"></i>
						</div>
					</li>
					<li class="aui-list-item">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-label" style="font-size: 14px;">检验计划</div>
							<input type="text" class="aui-input" placeholder="选择检验计划"
								style="width: 80%;font-size: 14px;" id="planName" value=""
								onclick="goSelectChkTask()">
							<i class="aui-input-addon aui-iconfont aui-icon-right" style="font-size: 1.6rem"></i>
						</div>
					</li>
				</ul>
                <div style="width:100%;margin-top:2%;"></div>
                <div class="aui-btn aui-btn-info aui-btn-block" onclick="createEquipTask()">生成任务单</div>
			</div>

		</div>
	</div>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script>
    var mntPlanId = "";
    var sonEquipId = "";
	var sonEquipName = "";

	apiready = function () {

	}
	//7；PDA自带扫描回车事件-设备编码
	$("#sm").on('keypress', function (e) { //#keyword为input文本框
		var keycode = e.keyCode;
		var sm = $(this).val();
		if (keycode == '13') {
			//设备编码
			$("#sm").val(sm);
			$("#sonEquip").val("");
			$("#planName").val("");
			mntPlanId = "";
    		sonEquipId = "";
			sonEquipName = "";
		}
	});

	function toScanner() {
		var moduleScanner = api.require('moduleScanner');
		var params = {
			top: 150,//扫描窗口的上边距
			width: 250,//扫描窗口的宽
			height: 250,//扫描窗口的高
			useColor: false,//是否使用自己设定的颜色(startColor和endColor),
			//如果不使用设定的颜色就使用默认的那张网格图
			startColor: '#0F08C8FF',//渐变起始颜色
			endColor: '#7F08C8FF',//渐变结束颜色
			animTime: 2200,//扫描动画时间,单位为毫秒
		};
		moduleScanner.toScannerActivityForResult(params, function (ret, err) {
			//console.log(JSON.stringify(ret));
			var SMequipCode = ret;
			var text = document.getElementById("sm");
			text.value = SMequipCode;
			$("#sonEquip").val("");
			$("#planName").val("");
			mntPlanId = "";
    		sonEquipId = "";
			sonEquipName = "";

		});

	}

	function goSelectChkTask() {
		var sonEquip = document.getElementById("sonEquip").value;
		if (sonEquip == '') {
			//如果为空
			alert("请先选择子设备编号");
			return;
		}
		var query = api.pageParam.query;
		var type = "";
		if(query.type!=undefined && query.type!=null && query.type!=""){
			type = query.type;
        }
		var url = "selMntPlan.html";
		var title = "点检任务列表";
		api.openWin({
			name: 'selMntPlan.html',
			url: url,
			pageParam: {
				url: url,
				title: title,
				SRequipCode: sonEquip,
				type :type,
                name: 'createEquipTask-TNK'
			}
		});
	}
	function goSelectSonEquip(){
		var SRequipCode = document.getElementById("sm").value;
		if (SRequipCode == '') {
			//如果为空
			alert("请先扫描/输入父资产编码");
			return;
		}
		var url = "selectSonEquip.html";
		var title = "点检任务列表";
		api.openWin({
			name: '点检任务列表',
			url: url,
			pageParam: {
				url: url,
				title: title,
				SRequipCode: SRequipCode,
                name: 'createEquipTask-TNK'
			}
		});
	}
	function setMntPlan(sysid,planName) {

        mntPlanId = sysid;
		$("#planName").attr("value", planName);

	}
    function setSonEquip(sysid,equipCode,equipName) {
        sonEquipId = sysid;
		sonEquipName = equipName;
        $("#sonEquip").attr("value", equipCode);

		var query = api.pageParam.query;
		var type = "";
		if(query.type!=undefined && query.type!=null && query.type!=""){
			type = query.type;
        }
		var serverUrl = localStorage.getItem('serverUrl');
		var url = serverUrl + "/app/getMntPlan";
		var un = localStorage.getItem('un');
		
		var params = new Object();
		params.url = url;
		params.method = 'post';
		params.dataType = 'json';
		params.returnAll = 'false';
		params.timeout = 60;
		
		var data = {
			values: { 
				un: un,
	            url: url,
	            SRequipCode: equipCode,
                type:type
	        }
		};
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {

                    var list = myobj.list;
                    var html = "";
					if(list != undefined && list != ""){
						for (var i = 0; i < list.length; i++) {
							mntPlanId = list[i].sysid;
							$("#planName").attr("value", list[i].planName);
                    }
					}

                } else if (myobj.code == '1') {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });


    }

	function createEquipTask() {
        var SRequipCode = document.getElementById("sm").value;
        var sonEquip = document.getElementById("sonEquip").value;
		var serverUrl = localStorage.getItem('serverUrl');
		var url = serverUrl + "/app/createEquipTask";
		var un = localStorage.getItem('un');
		// var pw = localStorage.getItem('pw');
		// var serverIp = localStorage.getItem('serverIp');
		// var serverPort = localStorage.getItem('serverPort');
		// var serverProject = localStorage.getItem('serverProject');
		// var url1 = serverIp+":"+serverPort+"/"+serverProject;
        var query = api.pageParam.query;
		var type = "";
		if(query.type!=undefined && query.type!=null && query.type!=""){
			type = query.type;
        }
        //设备非空校验
        if (SRequipCode == "" || SRequipCode == null || SRequipCode == undefined) {
            api.toast({
                msg: "请先扫描/输入 父资产编码",
                duration: 3000
            });
            return;
        }
        //子设备非空校验
        if (sonEquip == "" || sonEquip == null || sonEquip == undefined) {
            api.toast({
                msg: "请先选择 子设备编码",
                duration: 3000
            });
            return;
        }
        //计划非空校验
        if (mntPlanId == "" || mntPlanId == null || mntPlanId == undefined) {
            api.toast({
                msg: "请先选择 检验计划",
                duration: 3000
            });
            return;
        }
		var params = new Object();
		params.url = url;
		params.method = 'post';
		params.dataType = 'json';
		params.returnAll = 'false';
		params.timeout = 60;

		api.showProgress({
			title: '保存中...',
		});

		var data = {
			values: {
				un: un,
				// pw: pw,
				// url: url1,
				SRequipCode: sonEquip,
				mntPlanId: mntPlanId,
                type : type
			}
		};

		api.ajax({
			url: url,
			method: 'post',
			dataType: 'json',
			timeout: 300,
			returnAll: false,
			data: data
		}, function (ret, err) {
			if (ret) {
				var data = JSON.stringify(ret);
				var myobj = eval("(" + data + ")");
				//成功
				if (myobj.code == '0') {

					api.hideProgress();
					api.toast({
						msg: "保存成功",
						duration: 3000
					});
					var name = 'createEquipTask'
                    api.openWin({
                        name: 'uemChkTask-createEquipTask-tnk',
                        url: 'uemChkTask-createEquipTask-tnk.html',
                        pageParam: {
                            url: url,
                            title: title,
							name: name,
                            SRequipCode: sonEquip,
                            id :myobj.id,
                            equipId :sonEquipId,
							equipName :sonEquipName,
                            equipCode :myobj.equipCode,
                            taskResult :myobj.taskResult,
                            code : myobj.taskCode,
							type : type
                        }
                    });

				} else if (myobj.code == '1') {
					api.hideProgress();
					api.toast({
						msg: myobj.message,
						duration: 3000
					});
				}
			} else {
				api.hideProgress();
				alert(JSON.stringify(err));
			}
		});
	}
	
    function doSubmit(){

    }
	//返回按钮
	function closeWin() {
		api.closeWin({});
	}
</script>

</html>